﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.CodeDom;

namespace NMF.Languages.AnyText
{
    public abstract class TypeReference
    {
        public string Name { get; set; }

        public abstract CodeTypeReference CreateTypeReference();
    }

    public class Class : TypeReference
    {
        private Dictionary<string, Property> properties = new Dictionary<string, Property>();

        public Class BaseClass { get; private set; }

        void SetAssignableFrom(Class other)
        {

        }

        public TypeSystem TypeSystem { get; private set; }

        public Property GetProperty(string propertyName)
        {
            Property property;
            if (!properties.TryGetValue(propertyName, out property))
            {
                property = new Property(this, propertyName);
                properties.Add(propertyName, property);
            }
            return property;
        }

        public override CodeTypeReference CreateTypeReference()
        {
            return new CodeTypeReference(Name);
        }
    }

    public class Property
    {
        public Property(Class definingClass, string name)
        {
            DefiningClass = definingClass;
            Name = name;
        }
        public TypeReference Type { get; set; }
        public Class DefiningClass { get; private set; }
        public string Name { get; private set; }
        public bool IsCollectionProperty { get; set; }
        public TypeReference CollectionType { get; set; }
    }

    public class TypeSystem
    {
        private Dictionary<string, TypeReference> types;

        public TypeReference GetType(string typeName)
        {
            return types[typeName];
        }

        public Class GetCommonBase(Class class1, Class class2)
        {
            throw new NotImplementedException();
        }

        public Class GetClass(string p)
        {
            throw new NotImplementedException();
        }
    }

    public abstract class DataType : TypeReference
    {
        public abstract CodeExpression ParseValueExpression(string input);
    }
}
